package com.heeexy.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.config.annotation.RequiresPermissions;
import com.heeexy.example.service.IpMacService;
import com.heeexy.example.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: heeexy
 * @description: IP-MAC相关Controller
 * @date: 2017/10/24 16:04
 */
@RestController
@RequestMapping("/ipmac")
public class IpMacController {

    @Autowired
    private IpMacService ipMacService;

    /**
     * 查询IP-MAC列表
     */
    @RequiresPermissions("article:list")
    @GetMapping("/listIpMac")
    public JSONObject listIpMac(HttpServletRequest request) {
        return ipMacService.listIpMac(CommonUtil.request2Json(request));
    }

    /**
     * 新增IP-MAC
     */
    @RequiresPermissions("article:add")
    @PostMapping("/addIpMac")
    public JSONObject addIpMac(@RequestBody JSONObject requestJson) {
        CommonUtil.hasAllRequired(requestJson, "ip,seatNumber");
        return ipMacService.addIpMac(requestJson);
    }

    /**
     * 修改IP-MAC
     */
    @RequiresPermissions("article:update")
    @PostMapping("/updateIpMac")
    public JSONObject updateIpMac(@RequestBody JSONObject requestJson) {
        CommonUtil.hasAllRequired(requestJson, "id,ip,seatNumber");
        return ipMacService.updateIpMac(requestJson);
    }
}
